<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      div {
        width: 200px;
        height: 200px;
        background-color: skyblue;
      }
    </style>
  </head>
  <body>
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <script>
      //1.
      var divs = document.querySelectorAll("div");
      divs[0].onclick = function () {
        alert("niubi");
        this.onclick = null;
      };
      //2.
      divs[1].addEventListener("click", fn);
      function fn() {
        alert("niubi");
        divs[1].removeEventListener("click", fn);
      }
    </script>
  </body>
</html>
